<?php

namespace app\web\controller;
use app\web\model\AgentModel;
use app\web\model\LineGoodsModel;
use app\common\controller\StoreBaseController;
use think\Db;
/**商品发布
 */
class ShowController extends StoreBaseController
{
	protected $agent_model;
	protected $model;
	
    protected function _initialize() {
        parent::_initialize();
		$this->agent_model = new AgentModel();
		$this->model = new LineGoodsModel();
    }
	
    /**
     * 获取所有商品
     * @author [longx] 
     */
    public function index( $page = 1){
    	$store_id = session('storeInfo')['id'];
		$where['store_id'] = $store_id;
		if(request()->isPost()){
		 	$param = input('post.');
			if($param['goods_no']){
				$where['goods_no'] = ['like', '%'.$param['goods_no'].'%'];
			}
			if($param['goods_name']){
				$where['goods_name'] = ['like', '%'.$param['goods_name'].'%'];
			}
		}	
        $list = Db::name('line_goods')->where($where)->paginate(10);
        return $this->fetch('index', ['list' => $list]);
    }
	
	 /**
     * 
     *	疯狂抢页面
     * @author [longx] 
     */
	public function grabview(){
		$param = input('post.');
		//当前店铺信息
		$storeInfo = $this->agent_model->where('id',session('storeInfo')['id'])->find();
		//疯狂抢商品信息		
		$prabgood = $this->model->where('id',session('storeInfo')['id'])->find(input('id'));
		$this->assign('score',$storeInfo['score']);
		$this->assign('id',input('id'));
		$this->assign('prabgood',$prabgood);
		return $this->fetch();
	}
	
	/**
     * 
     *	保存疯狂抢
     * @author [longx] 
     */
	public function savegrab(){
		$param = input();
		$id = input('id');
		if ($this->model->allowField(true)->save($param,$id) !== false) {		
			return json(['code'=>200,'msg'=>"操作成功"]);
		}else{
			return json(['code'=>408,'msg'=>"操作失败"]);
		}
	}
	
	/**
     * 
     *	赚积分页面
     * @author [longx]
     */
	public function scoreview(){
		$param = input('post.');
		//当前店铺信息
		$storeInfo = $this->agent_model->where('id',session('storeInfo')['id'])->find();
		//赚积分商品信息		
		$scoregood = $this->model->where('id',session('storeInfo')['id'])->find(input('id'));
		$this->assign('score',$storeInfo['score']);
		$this->assign('id',input('id'));
		$this->assign('scoregood',$scoregood);
		return $this->fetch();
	}
	
	/**
     * 
     *	保存赚积分
     * @author [longx] 
     */
	public function savescore(){
		$param = input();
		$id = input('id');
		if ($this->model->allowField(true)->save($param,$id) !== false) {		
			return json(['code'=>200,'msg'=>"操作成功"]);
		}else{
			return json(['code'=>408,'msg'=>"操作失败"]);
		}
	}
	
	/**
     * 
     *	优惠购页面
     * @author [longx]
     */
	public function agioview(){
		$param = input('post.');
		//当前店铺信息
		$storeInfo = $this->agent_model->where('id',session('storeInfo')['id'])->find();
		//赚积分商品信息		
		$agiogood = $this->model->where('id',session('storeInfo')['id'])->find(input('id'));
		$this->assign('score',$storeInfo['score']);
		$this->assign('id',input('id'));
		$this->assign('agiogood',$agiogood);
		return $this->fetch();
	}
	
	/**
     * 
     *	保存优惠购
     * @author [longx] 
     */
	public function saveagio(){
		$param = input();
		$id = input('id');
		if ($this->model->allowField(true)->save($param,$id) !== false) {		
			return json(['code'=>200,'msg'=>"操作成功"]);
		}else{
			return json(['code'=>408,'msg'=>"操作失败"]);
		}
	}
	
	/**
     * 
     *	云拼团页面
     * @author [longx]
     */
	public function ptview(){
		$param = input('post.');
		//当前店铺信息
		$storeInfo = $this->agent_model->where('id',session('storeInfo')['id'])->find();
		//赚积分商品信息		
		$ptgood = $this->model->where('id',session('storeInfo')['id'])->find(input('id'));
		$this->assign('score',$storeInfo['score']);
		$this->assign('id',input('id'));
		$this->assign('ptgood',$ptgood);
		return $this->fetch();
	}
	
	/**
     * 
     *	保存云拼团
     * @author [longx] 
     */
	public function savept(){
		$param = input();
		$id = input('id');
		if ($this->model->allowField(true)->save($param,$id) !== false) {		
			return json(['code'=>200,'msg'=>"操作成功"]);
		}else{
			return json(['code'=>408,'msg'=>"操作失败"]);
		}
	}
	
	/**
     * 
     *	交友团页面
     * @author [longx]
     */
	public function jytview(){
		$param = input('post.');
		//当前店铺信息
		$storeInfo = $this->agent_model->where('id',session('storeInfo')['id'])->find();
		//赚积分商品信息		
		$jytgood = $this->model->where('id',session('storeInfo')['id'])->find(input('id'));
		$this->assign('score',$storeInfo['score']);
		$this->assign('id',input('id'));
		$this->assign('jytgood',$jytgood);
		return $this->fetch();
	}
	
	/**
     * 
     *	保存交友团
     * @author [longx] 
     */
	public function savejyt(){
		$param = input();
		$id = input('id');
		if ($this->model->allowField(true)->save($param,$id) !== false) {		
			return json(['code'=>200,'msg'=>"操作成功"]);
		}else{
			return json(['code'=>408,'msg'=>"操作失败"]);
		}
	}
	
	/**
     * 
     *	秒杀页面
     * @author [longx]
     */
	public function msview(){
		$param = input('post.');
		//当前店铺信息
		$storeInfo = $this->agent_model->where('id',session('storeInfo')['id'])->find();
		//赚积分商品信息		
		$msgood = $this->model->where('id',session('storeInfo')['id'])->find(input('id'));
		$this->assign('score',$storeInfo['score']);
		$this->assign('id',input('id'));
		$this->assign('msgood',$msgood);
		return $this->fetch();
	}
	
	/**
     * 
     *	保存秒杀
     * @author [longx] 
     */
	public function savems(){
		$param = input();
		$id = input('id');
		$param['limit1'] = input('limit1') ? true : false;
		$param['limit2'] = input('limit2') ? true : false;
		$param['limit3'] = input('limit3') ? true : false;
		if ($this->model->allowField(true)->save($param,$id) !== false) {		
			return json(['code'=>200,'msg'=>"操作成功"]);
		}else{
			return json(['code'=>408,'msg'=>"操作失败"]);
		}
	}
}
